#include <Editor/StdAfx.h>
#include "NewSceneDialog.h"
#include "GameToolApp.h"
#include "../GameLib/math.h"

NewSceneDialog::NewSceneDialog(wxWindow* parent, wxWindowID id, const wxString& title, const wxSize& size)
	: wxDialog(parent, id, title, wxDefaultPosition, size)

{
	wxBoxSizer* topSizer = new wxBoxSizer( wxVERTICAL);
	SetSizer(topSizer);

	// TERRAIN CREATION START ---
		wxStaticBoxSizer* creationSizer =new wxStaticBoxSizer(new wxStaticBox(this, wxID_ANY, _("Terrain Creation")), wxVERTICAL);
		topSizer->Add(creationSizer, wxSizerFlags().Expand().Border());
		// TerrainSize
		wxBoxSizer* terrainSizeSizer = new wxBoxSizer( wxHORIZONTAL );
		creationSizer->Add(terrainSizeSizer);
		terrainSizeSizer->Add(new wxStaticText(this, wxID_ANY, _("TerrainSize: ")), wxSizerFlags().Border());
		mTerrainSizeText = new wxTextCtrl(this, wxID_ANY, _T("257"));
		terrainSizeSizer->Add(mTerrainSizeText, wxSizerFlags().Border());
		terrainSizeSizer->Add(new wxStaticText(this, wxID_ANY, _("vertices")), wxSizerFlags().Border());
		// WorldSize
		wxBoxSizer* worldSizeSizer = new wxBoxSizer( wxHORIZONTAL );
		creationSizer->Add(worldSizeSizer);
		worldSizeSizer->Add(new wxStaticText(this, wxID_ANY, _("WorldSize: ")), wxSizerFlags().Border());
		mWorldSizeText = new wxTextCtrl(this, wxID_ANY, _T("150"));
		worldSizeSizer->Add(mWorldSizeText, wxSizerFlags().Border());
		worldSizeSizer->Add(new wxStaticText(this, wxID_ANY, _("meter")), wxSizerFlags().Border());

	// --- TERRAIN CREATION END

	wxSizer* buttonSizer = CreateButtonSizer(wxOK|wxCANCEL);
	topSizer->Add(buttonSizer, wxSizerFlags().Border().Center());
	Layout();
	mTerrainSizeText->SetFocus();
}

float NewSceneDialog::GetWorldSize()
{
	double val;
	bool success = mWorldSizeText->GetValue().ToDouble(&val);
	if (success)
	{
		return (float)val;
	}
	else
	{
		wxGetApp().Message(_("World size has wrong value. Forced to 150m"));
		return 150.0f;
	}
}

int NewSceneDialog::GetTerrainSize()
{
	long val;
	bool success = mTerrainSizeText->GetValue().ToLong(&val);
	if (success)
	{
		if (!PowerOfTwo(val - 1))
		{
			val = 513;
			wxGetApp().Message(_("Terrain size should be power of two. Forced to 513"));
		}
		return (int)val;
	}
	else
	{
		wxGetApp().Message(_("Terrain size has worng value. Forced to 513"));
		return 513;
	}
}